button: Remove priv pointer
authorTimm Bäder <mail@baedert.org>
Sun, 25 Feb 2018 10:29:33 +0000 (11:29 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 25 Feb 2018 15:47:20 +0000 (16:47 +0100)
This way we can also move the GtkButtonPrivate definition into
gtkbutton.c

gtk/gtkbutton.c
gtk/gtkbutton.h
gtk/gtkbuttonprivate.h
gtk/gtkmenubutton.c
gtk/gtkscalebutton.c
gtk/gtkstackswitcher.c

index 5c4ba4308a317d759e6a687c91e40e8bf5b58323..b5803375d71c46091381136dd535c48b92fb0b91 100644 (file)
  */
 #define ACTIVATE_TIMEOUT 250
 
+struct _GtkButtonPrivate
+{
+  GtkActionHelper       *action_helper;
+
+  GdkDevice             *grab_keyboard;
+
+  GtkGesture            *gesture;
+
+  guint                  activate_timeout;
+
+  guint          button_down           : 1;
+  guint          in_button             : 1;
+  guint          use_underline         : 1;
+  guint          child_type            : 2;
+};
 
 enum {
   CLICKED,
@@ -158,8 +173,9 @@ static void
 gtk_button_add (GtkContainer *container, GtkWidget *child)
 {
   GtkButton *button = GTK_BUTTON (container);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
-  if (button->priv->child_type != WIDGET_CHILD)
+  if (priv->child_type != WIDGET_CHILD)
     gtk_container_remove (container, gtk_bin_get_child (GTK_BIN (button)));
 
   gtk_button_set_child_type (button, WIDGET_CHILD);
@@ -180,7 +196,10 @@ gtk_button_remove (GtkContainer *container, GtkWidget *child)
 static void
 gtk_button_unmap (GtkWidget *widget)
 {
-  GTK_BUTTON (widget)->priv->in_button = FALSE;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (GTK_BUTTON (widget));
+
+  priv->in_button = FALSE;
+
   GTK_WIDGET_CLASS (gtk_button_parent_class)->unmap (widget);
 }
 
@@ -295,7 +314,7 @@ multipress_pressed_cb (GtkGestureMultiPress *gesture,
                        GtkWidget            *widget)
 {
   GtkButton *button = GTK_BUTTON (widget);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (gtk_widget_get_focus_on_click (widget) && !gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
@@ -345,12 +364,12 @@ multipress_released_cb (GtkGestureMultiPress *gesture,
                         GtkWidget            *widget)
 {
   GtkButton *button = GTK_BUTTON (widget);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GdkEventSequence *sequence;
 
   gtk_button_do_release (button,
                          gtk_widget_is_sensitive (GTK_WIDGET (button)) &&
-                         (button->priv->in_button ||
+                         (priv->in_button ||
                           touch_release_in_button (button)));
 
   sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
@@ -367,7 +386,7 @@ multipress_gesture_update_cb (GtkGesture       *gesture,
                               GdkEventSequence *sequence,
                               GtkButton        *button)
 {
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   gboolean in_button;
   gdouble x, y;
 
@@ -412,10 +431,7 @@ gtk_button_set_child_type (GtkButton *button, guint child_type)
 static void
 gtk_button_init (GtkButton *button)
 {
-  GtkButtonPrivate *priv;
-
-  button->priv = gtk_button_get_instance_private (button);
-  priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   gtk_widget_set_can_focus (GTK_WIDGET (button), TRUE);
   gtk_widget_set_receives_default (GTK_WIDGET (button), TRUE);
@@ -442,7 +458,7 @@ static void
 gtk_button_finalize (GObject *object)
 {
   GtkButton *button = GTK_BUTTON (object);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   g_clear_object (&priv->gesture);
 
@@ -453,7 +469,7 @@ static void
 gtk_button_dispose (GObject *object)
 {
   GtkButton *button = GTK_BUTTON (object);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   g_clear_object (&priv->action_helper);
 
@@ -465,15 +481,16 @@ gtk_button_set_action_name (GtkActionable *actionable,
                             const gchar   *action_name)
 {
   GtkButton *button = GTK_BUTTON (actionable);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
-  if (!button->priv->action_helper)
-    button->priv->action_helper = gtk_action_helper_new (actionable);
+  if (!priv->action_helper)
+    priv->action_helper = gtk_action_helper_new (actionable);
 
   g_signal_handlers_disconnect_by_func (button, gtk_real_button_clicked, NULL);
   if (action_name)
     g_signal_connect_after (button, "clicked", G_CALLBACK (gtk_real_button_clicked), NULL);
 
-  gtk_action_helper_set_action_name (button->priv->action_helper, action_name);
+  gtk_action_helper_set_action_name (priv->action_helper, action_name);
 }
 
 static void
@@ -481,11 +498,12 @@ gtk_button_set_action_target_value (GtkActionable *actionable,
                                     GVariant      *action_target)
 {
   GtkButton *button = GTK_BUTTON (actionable);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
-  if (!button->priv->action_helper)
-    button->priv->action_helper = gtk_action_helper_new (actionable);
+  if (!priv->action_helper)
+    priv->action_helper = gtk_action_helper_new (actionable);
 
-  gtk_action_helper_set_action_target_value (button->priv->action_helper, action_target);
+  gtk_action_helper_set_action_target_value (priv->action_helper, action_target);
 }
 
 static void
@@ -529,7 +547,7 @@ gtk_button_get_property (GObject         *object,
                          GParamSpec      *pspec)
 {
   GtkButton *button = GTK_BUTTON (object);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   switch (prop_id)
     {
@@ -561,16 +579,18 @@ static const gchar *
 gtk_button_get_action_name (GtkActionable *actionable)
 {
   GtkButton *button = GTK_BUTTON (actionable);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
-  return gtk_action_helper_get_action_name (button->priv->action_helper);
+  return gtk_action_helper_get_action_name (priv->action_helper);
 }
 
 static GVariant *
 gtk_button_get_action_target_value (GtkActionable *actionable)
 {
   GtkButton *button = GTK_BUTTON (actionable);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
-  return gtk_action_helper_get_action_target_value (button->priv->action_helper);
+  return gtk_action_helper_get_action_target_value (priv->action_helper);
 }
 
 static void
@@ -726,7 +746,7 @@ static void
 gtk_button_unrealize (GtkWidget *widget)
 {
   GtkButton *button = GTK_BUTTON (widget);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (priv->activate_timeout)
     gtk_button_finish_activate (button, FALSE);
@@ -738,7 +758,7 @@ static void
 gtk_button_do_release (GtkButton *button,
                        gboolean   emit_clicked)
 {
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (priv->button_down)
     {
@@ -759,7 +779,7 @@ gtk_button_key_release (GtkWidget   *widget,
                        GdkEventKey *event)
 {
   GtkButton *button = GTK_BUTTON (widget);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (priv->activate_timeout)
     {
@@ -775,7 +795,7 @@ gtk_button_key_release (GtkWidget   *widget,
 static void
 gtk_real_button_clicked (GtkButton *button)
 {
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (priv->action_helper)
     gtk_action_helper_activate (priv->action_helper);
@@ -793,7 +813,7 @@ static void
 gtk_real_button_activate (GtkButton *button)
 {
   GtkWidget *widget = GTK_WIDGET (button);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GdkDevice *device;
 
   device = gtk_get_current_event_device ();
@@ -824,7 +844,7 @@ gtk_button_finish_activate (GtkButton *button,
                            gboolean   do_it)
 {
   GtkWidget *widget = GTK_WIDGET (button);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   g_source_remove (priv->activate_timeout);
   priv->activate_timeout = 0;
@@ -954,12 +974,10 @@ void
 gtk_button_set_use_underline (GtkButton *button,
                              gboolean   use_underline)
 {
-  GtkButtonPrivate *priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   g_return_if_fail (GTK_IS_BUTTON (button));
 
-  priv = button->priv;
-
   use_underline = use_underline != FALSE;
 
   if (use_underline != priv->use_underline)
@@ -991,15 +1009,17 @@ gtk_button_set_use_underline (GtkButton *button,
 gboolean
 gtk_button_get_use_underline (GtkButton *button)
 {
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
+
   g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
 
-  return button->priv->use_underline;
+  return priv->use_underline;
 }
 
 static void
 gtk_button_update_state (GtkButton *button)
 {
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GtkStateFlags new_state;
   gboolean depressed;
 
@@ -1020,11 +1040,8 @@ static void
 gtk_button_display_changed (GtkWidget  *widget,
                             GdkDisplay *previous_display)
 {
-  GtkButton *button;
-  GtkButtonPrivate *priv;
-
-  button = GTK_BUTTON (widget);
-  priv = button->priv;
+  GtkButton *button = GTK_BUTTON (widget);
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   /* If the button is being pressed while the display changes the
     release might never occur, so we reset the state. */
@@ -1050,7 +1067,7 @@ gtk_button_grab_notify (GtkWidget *widget,
                        gboolean   was_grabbed)
 {
   GtkButton *button = GTK_BUTTON (widget);
-  GtkButtonPrivate *priv = button->priv;
+  GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
   if (priv->activate_timeout &&
       priv->grab_keyboard &&
index 6be47145fc3992bc427ee85c96a5e22ae1acd5ff..51f9bac0a7ee84ea74dedcd88b5a60d1af00590d 100644 (file)
@@ -31,8 +31,6 @@
 #endif
 
 #include <gtk/gtkbin.h>
-#include <gtk/gtkimage.h>
-
 
 G_BEGIN_DECLS
 
@@ -50,9 +48,7 @@ typedef struct _GtkButtonClass        GtkButtonClass;
 struct _GtkButton
 {
   /*< private >*/
-  GtkBin bin;
-
-  GtkButtonPrivate *priv;
+  GtkBin parent_instance;
 };
 
 /**
index e19cc964052d3224500bf4f408f9ae248adb178c..cc2759f25b234f73f41f0fe4b19e09e465c3c571 100644 (file)
 
 #include "gtkbutton.h"
 
-#include "gtkactionhelperprivate.h"
-#include "gtkgesturesingle.h"
-
-G_BEGIN_DECLS
-
-
-struct _GtkButtonPrivate
-{
-  GtkActionHelper       *action_helper;
-
-  GdkDevice             *grab_keyboard;
-
-  GtkGesture            *gesture;
-
-  guint                  activate_timeout;
-
-  guint          button_down           : 1;
-  guint          in_button             : 1;
-  guint          use_underline         : 1;
-  guint          child_type            : 2;
-};
+#include "gtkgesture.h"
 
 GtkGesture * gtk_button_get_gesture (GtkButton *button);
 
-G_END_DECLS
-
 #endif /* __GTK_BUTTON_PRIVATE_H__ */
index 35d9dca1f9ff7b9986601db827164692c2c61fb2..1254ed68e8ac5777fbf70376afba42efb59d9f4b 100644 (file)
 
 #include "gtkmenubutton.h"
 #include "gtkmenubuttonprivate.h"
-#include "gtkbuttonprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkwindow.h"
+#include "gtkimage.h"
+#include "gtkactionable.h"
 #include "gtkmain.h"
 #include "gtkaccessible.h"
 #include "gtkpopover.h"
@@ -667,7 +668,7 @@ update_sensitivity (GtkMenuButton *menu_button)
 {
   GtkMenuButtonPrivate *priv = menu_button->priv;
 
-  if (GTK_BUTTON (menu_button)->priv->action_helper)
+  if (gtk_actionable_get_action_name (GTK_ACTIONABLE (menu_button)) != NULL)
     return;
 
   gtk_widget_set_sensitive (GTK_WIDGET (menu_button),
index 9f9a7e93d0e3c9a9f94348a88de639dc25c5eff1..91f8dacf226e974aded1fa55e1598d676bdd19be 100644 (file)
@@ -40,6 +40,7 @@
 #include "gtkbindings.h"
 #include "gtkbox.h"
 #include "gtkbuttonprivate.h"
+#include "gtkimage.h"
 #include "gtkeventcontrollerscroll.h"
 #include "gtkframe.h"
 #include "gtkgesture.h"
index 7c403c3c40a2c2434a5b6a3c3a88e9a11d6e1f73..2c7566e61f8c1476c59b85f08d96d1e8e6effc48 100644 (file)
@@ -28,6 +28,7 @@
 #include "gtkintl.h"
 #include "gtkwidgetprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkimage.h"
 
 /**
  * SECTION:gtkstackswitcher